<?php
include $_SERVER['DOCUMENT_ROOT'].'/fr/include/init.php';
include $_SERVER['DOCUMENT_ROOT'].'/fr/include/require_login.php';
if($_POST['q']=="upd"){
	// User
	mysql_query("UPDATE `user` SET `user_id` = UPPER('".$_POST['email']."'),
				`user_password` = UPPER('".$_POST['password']."'),
				`user_title` = UPPER('".$_POST['title']."'),
				`user_firstname` = UPPER('".$_POST['adr_firstname']."'),
				`user_lastname` = UPPER('".$_POST['adr_lastname']."'),
				`user_birthdate` = UPPER('".$_POST['birthyear']."-".$_POST['birthmonth']."-".$_POST['birthday']."'),
				`user_address` = UPPER('".$_POST['email']."_0'),
				`user_liv_address` = UPPER('".$_POST['email']."_0')
				WHERE `user_id` = '".$_SESSION['user_id']."';");
	mysql_query("UPDATE `cart` SET `user_id` = UPPER('".$_POST['email']."')
				WHERE `user_id` = '".$_SESSION['user_id']."';");
	// Adresse
	mysql_query("REPLACE INTO `user_address` (
				`adr_id` ,`adr_type` ,`adr_title` ,`adr_firstname` ,`adr_lastname` ,`adr_company` ,`adr_address` ,`adr_zipcode` ,`adr_city` ,`adr_country` ,`adr_phone` ,`adr_cellphone`)
				VALUES (UPPER('".$_POST['email']."_0') , 'user', UPPER('".$_POST['adr_title']."'), UPPER('".$_POST['adr_firstname']."'), UPPER('".$_POST['adr_lastname']."'), UPPER('".$_POST['adr_company']."'), UPPER('".$_POST['adr_address']."'), UPPER('".$_POST['adr_zipcode']."'), UPPER('".$_POST['adr_city']."'), UPPER('".$_POST['adr_country']."'), UPPER('".$_POST['adr_phone']."'), UPPER('".$_POST['adr_cellphone']."'));");
	// Livraison
	if($_POST['useliv']=="on"){
		mysql_query("REPLACE INTO `user_address` (
				`adr_id` ,`adr_type` ,`adr_title` ,`adr_firstname` ,`adr_lastname` ,`adr_company` ,`adr_address` ,`adr_zipcode` ,`adr_city` ,`adr_country` ,`adr_phone` ,`adr_cellphone`)
				VALUES (UPPER('".$_POST['email']."_1') , 'liv', UPPER('".$_POST['liv_title']."'), UPPER('".$_POST['liv_firstname']."'), UPPER('".$_POST['liv_lastname']."'), UPPER('".$_POST['liv_company']."'), UPPER('".$_POST['liv_address']."'), UPPER('".$_POST['liv_zipcode']."'), UPPER('".$_POST['liv_city']."'), UPPER('".$_POST['liv_country']."'), UPPER('".$_POST['liv_phone']."'), UPPER('".$_POST['liv_cellphone']."'));");
		
		mysql_query("UPDATE `user` SET `user_liv_address` = UPPER('".$_POST['email']."_1') WHERE `user_id` = '".$_POST['email']."';");
	} else {
		mysql_query("UPDATE `user` SET `user_liv_address` = UPPER('".$_POST['email']."_0') WHERE `user_id` = '".$_POST['email']."';");
	}
	// Connexion
	$_POST['query'] = 'update';
	$_POST['log_email'] = $_POST['email'];
	$_POST['log_pwd'] = $_POST['password'];
	include $_SERVER['DOCUMENT_ROOT'].'/fr/include/login.php';
}
if($_POST['callback'] == "val"){
	header("location: /fr/validation.php" );
} else if($_POST['callback'] == "com"){
	header("location: /fr/moncompte/" );
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<? include $_SERVER['DOCUMENT_ROOT'].'/fr/include/meta.php'; ?>
	<meta name="description" content="Herbes de Chine : Mes informations personnelles" />
	<meta name="keywords" content="Herbes de chine, informations personnelles,compte,suivi,mon compte,profil,historique,historique des commandes,commandes en cours" />
	<title>Herbes de Chine : Mes informations personnelles</title>
	<link href="/fr/css/common.css" rel="stylesheet" type="text/css" />
	<link href="/fr/css/inside.css" rel="stylesheet" type="text/css" />
	<script language="javascript" type="text/javascript" src="/fr/js/static.js"></script>
</head>
<body>
	<? include $_SERVER['DOCUMENT_ROOT'].'/fr/include/header.php'; ?>
    <div id="tools">
    	<table>
        	<tr>
            	<td id="chemin"><a href="/fr/index.html">Accueil</a> > Mon panier</td>
                <td id="search">
					<? include $_SERVER['DOCUMENT_ROOT'].'/fr/include/displaytoolbar.php'; ?>


				</td>
            </tr>
        </table>
    </div>
	<p class="parag">* Les champs munis d'un astérisque sont obligatoires et nécessaires à l'envoi de la commande.</p>
	<table id="body" class="widescreen">
		<tr class="top"><td colspan="2"></td></tr>
	    <tr class="middle"><td class="content">
			<form name="form" action="?" method="POST">
			<input class="text" type="hidden" name="q" value="upd" />
			<?php 
			if($_GET['cal']=="val"){
				echo '<input type="hidden" name="callback" value="val" />';
			} else if($_GET['cal']=="com"){
				echo '<input type="hidden" name="callback" value="com" />';
			}
			include $_SERVER['DOCUMENT_ROOT'].'/fr/include/form.php'; ?>
			<table class="clear">
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr>
					<td></td>
					<td class="addcart aright">
					<?
					if($_GET['cal']=="val"){
						echo "<a href='/fr/validation.php'><img src='/img/common/retour.gif' alt='Retour' /></a>";
					} else if($_GET['cal']=="com"){
						echo "<a href='/fr/moncompte/'><img src='/img/common/retour.gif' alt='Retour' /></a>";
					}
					?>
					<a href="#" onClick="validForm();return false;"><img src="/img/common/enregistrer.gif" alt="Enregistrer" /></a></td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
			</table>
		</form>
		</td></tr>
		<tr class="bottom"><td colspan="2"></td></tr>
	</table><br />
	<? include $_SERVER['DOCUMENT_ROOT'].'/fr/include/footer.php'; ?>
</body>
</html>
